package cn.codesugar.service

import android.content.Intent
import android.util.Log
import androidx.core.app.JobIntentService

private const val TAG = "MyJobIntentService"

/**
 * Android O之前和IntentService效果一样
 * 但是Android O以后JobIntentService不会立即执行，等手机进入一定状态后才会执行任务，所以不能用来执行及时的后台任务
 */
class MyJobIntentService : JobIntentService() {
    override fun onHandleWork(intent: Intent) {
        // 打印当前线程的id
        Log.e(TAG, "onHandleIntent() executed, Thread id is ${Thread.currentThread().name}")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(TAG, "onDestroy executed")
    }

}